import {
  getManyByFiledDto,
  idByGetDto,
  idByPostDto,
  idsArrayDto,
  likeDto,
  pageOrSortDto,
} from '@/lib/dto/baseDto';
import { ApiProperty } from '@nestjs/swagger';
import {
  IsIn,
  IsInt,
  isNotEmpty,
  IsNotEmpty,
  IsNotEmptyObject,
  IsObject,
  IsString,
} from 'class-validator';

/**
 * delete many Dto
 */
export class SysDeleteManyDto extends idsArrayDto {}

/**
 * SysListDto Dto  method : get
 */
export class SysListPageOrSortDto extends pageOrSortDto {}

/**
 * findById Dto  method : get
 */
export class SysFindByIdDto extends idByGetDto {}
/**
 * like Dto  method : get
 */
export class SysLikeDto extends likeDto {}

export class SysInsertDto {
  @IsNotEmpty({ message: '操作用户不能为空' })
  @IsString()
  @ApiProperty({ type: 'string', example: 'admin' })
  who: string;

  @IsNotEmpty({ message: '通过哪个路由操作不能为空' })
  @IsString()
  @ApiProperty({ type: 'string', example: 'url' })
  action_controller: string;

  @IsNotEmpty({ message: '操作内容不能为空' })
  @IsString()
  @ApiProperty({ type: 'string', example: '删除' })
  action: string;
}

/**
 * update Dto  取决于是只更新一个数据还是说把带有更新数据的对象整个传过来，
 * 后者的话，这里就好写了。
 */
export class SysUpdateDto extends idByPostDto {
  @IsNotEmptyObject({}, { message: '要更新的数据不能为空' })
  @IsObject({ message: '要更新的数据需要是对象' })
  @ApiProperty({
    example: {
      who: 'xxx',
      action_controller: 'sysController',
      action: '更新',
    },
  })
  newData: object;
}
/**
 * SetState Dto  method : post
 */
export class SysSetStateDto extends idByPostDto {
  @IsNotEmpty({ message: 'state不能为空' })
  @IsInt({ message: '需要是整数' })
  @IsIn([0, 1], { message: '只能是0或者1' })
  @ApiProperty({ example: 0 })
  state: number;
}

/**
 * SysFindManyByFiledDto Dto  method : Get
 */
export class SysFindManyByFiledDto extends getManyByFiledDto {}

/**
 * token
 */
export class tokenDto {
  @ApiProperty({
    example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7Im5hbWUiOiJ3YW5namluZyIsInBhc3N3b3JkIjoid2FuZ2ppbmcxMjMifSwiaWF0IjoxNjM3NzM0MjkwLCJleHAiOjE2Mzc3Mzc4OTAsImlzcyI6IndhbmdqaW5nIn0.rBGjE2KD_ncSoy6kh6yOvqX_qCkOWvuTOupe0iD9XB8"
  })
  token: string;
}
